package org.example.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.example.entity.RuleEntity;
import java.util.List;

@Mapper
public interface RuleDao extends BaseMapper<RuleEntity> {
    // 插入一条规则
    @Insert("INSERT INTO ruletable (rule_name, rule_question_type, rule_grade, rule_difficulty, rule_points, create_by, create_time) " +
            "VALUES (#{ruleName}, #{ruleQuestionType}, #{ruleGrade}, #{ruleDifficulty}, #{rulePoints}, #{createBy}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "ruleId", keyColumn = "rule_id")
    int createRule(RuleEntity rule);

    // 根据 ID 更新规则
    @Update("UPDATE ruletable SET " +
            "rule_name = #{rule.ruleName}, " +
            "rule_question_type = #{rule.ruleQuestionType}, " +
            "rule_grade = #{rule.ruleGrade}, " +
            "rule_difficulty = #{rule.ruleDifficulty}, " +
            "rule_points = #{rule.rulePoints}, " +
            "create_by = #{rule.createBy}, " +
            "create_time = #{rule.createTime} " +
            "WHERE rule_id = #{id}")
    int updateRule(@Param("id") Integer id, @Param("rule") RuleEntity rule);

    // 根据 ID 删除规则
    @Delete("DELETE FROM ruletable WHERE rule_id = #{id}")
    int deleteRule(@Param("id") Integer id);

    // 根据 ID 查询规则
    @Select("SELECT * FROM ruletable WHERE rule_id = #{id}")
    RuleEntity selectRule(@Param("id") Integer id);

    // 查询所有规则
    @Select("SELECT * FROM ruletable")
    List<RuleEntity> getAllRules();
}
